package avicit.im.lantop.basic.lexiconManager.rest;


import avicit.im.lantop.basic.companycorrespondence.rest.CompanyCorrespondenceServiceRest;
import avicit.im.lantop.basic.lexiconManager.service.LantopLexiconService;
import avicit.im.lantop.basic.lexiconManager.service.api.LantopLexiconServiceApi;
import avicit.im.lantop.basic.themewordmanager.domain.LantopThemeWord;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.rest.msg.ResponseMsg;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags = "LantopLexiconService", description = "LantopLexiconService")
@RequestMapping("/api/avicit/im/lantop/basic/lexiconManager/rest/LantopLexiconServiceRest")
public class LantopLexiconServiceRest {



    private static final Logger LOGGER = LoggerFactory.getLogger(LantopLexiconServiceRest.class);


    @Autowired(required = true)
    private LantopLexiconService themeWordService;



    /**
     *查询是否有重复的关键词
     * @param map
     * @return
     */
    @PostMapping("/getCount")
    @ApiOperation(value = "查询是否有重复的关键词")
    public ResponseMsg<Integer> getCount(@ApiParam(value = "查询是否有重复的关键词", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String formalThemeWord = (String) map.get("formalThemeWord");
            String id = (String) map.get("id");
            int count = themeWordService.getCount(orgId, formalThemeWord, id);
            responseMsg.setResponseBody(count);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 修改数据
     * @param map
     * @return
     */
    @PostMapping("/updateData")
    @ApiOperation(value = "修改数据")
    public ResponseMsg updateData(@ApiParam(value = "修改数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            LantopThemeWord themeWord = (LantopThemeWord) map.get("themeWord");
            themeWordService.updateData(themeWord);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存数据
     * @param map
     * @return
     */
    @PostMapping("/insertData")
    @ApiOperation(value = "保存数据")
    public ResponseMsg insertData(@ApiParam(value = "保存数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            LantopThemeWord themeWord = (LantopThemeWord) map.get("themeWord");
            themeWordService.insertData(themeWord);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除数据
     * @param map
     * @return
     */
    @PostMapping("/deleteThemeWord")
    @ApiOperation(value = "删除数据")
    public ResponseMsg deleteThemeWord(@ApiParam(value = "删除数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String ids = (String) map.get("ids");
            themeWordService.deleteThemeWord(ids);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 获取数据
     * @param map
     * @return
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "获取数据")
    public ResponseMsg<Page<LantopThemeWord>> getPageList(@ApiParam(value = "获取数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<Page<LantopThemeWord>> responseMsg = new ResponseMsg<>();
        try {
            Page<LantopThemeWord> page = (Page<LantopThemeWord>) map.get("page");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            Page<LantopThemeWord> pageList = themeWordService.getPageList(page, parameter);
            responseMsg.setResponseBody(pageList);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }
}
